package task3.erode;

import java.awt.Label;
import java.util.Vector;
import task3.pimpmypipe.Writeable;
import task3.util.AbstractBean;
import task3.util.FilterObservable;
import task3.util.ImageTO;
import task3.util.InputEvent;
import task3.util.InputListener;

public class BErode
  extends AbstractBean
  implements InputListener
{
  private static final long serialVersionUID = -4459458681786239831L;
  private ErodeFilter _filter;
  
  public BErode()
  {
    this._filter = new ErodeFilter();
    this._filter.getObservable().addObserver(this);
    this._textField.setText("Erode filter");
  }
  
  public void inputChanged(InputEvent event)
  {
    this._filter.setInput(event.getSource());
    run();
  }
  
  public void addListener(InputListener l)
  {
    this._listeners.add(l);
    
    this._filter.setOutput(l.getWriteable());
    
    InputEvent event = new InputEvent(this._filter);
    for (InputListener i : this._listeners) {
      i.inputChanged(event);
    }
    run();
  }
  
  public void removeListener(InputListener l)
  {
    this._listeners.remove(l);
  }
  
  public Writeable<ImageTO> getWriteable()
  {
    return this._filter;
  }
  
  public void run()
  {
    try
    {
      this._filter.run();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public int getKernelSize()
  {
    return this._filter.getKernelSize();
  }
  
  public void setKernelSize(int kernelSize)
  {
    this._filter.setKernelSize(kernelSize);
    run();
  }
}
